package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo12 {
    public static void main(String[] args) {
        Connection connection = null;
        try {
            connection = DBUtil.getConnection();
            connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            connection.setAutoCommit(false);
            PreparedStatement ps = connection.prepareStatement("INSERT INTO userinfo (username ,password ,nickename ,age)" +
                    "VALUES (?,?,?,?)");
            ps.setString(1,"jcak");
            ps.setString(2,"8899000");
            ps.setString(3,"mr.j");
            ps.setInt(4,33);
            int i = ps.executeUpdate();
            System.out.println(i>0?"插入成功":"插入失败");
            connection.commit();
        } catch (SQLException e) {
            try {
                connection.rollback();
            } catch (SQLException ex) {
                e.printStackTrace();
            }
        }finally {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }
}
